package easy;

import java.util.ArrayList;
import java.util.List;

/**
 * @author admin
 * 1389. 按既定顺序创建目标数组
 * 解题思路：先用一个list保存要求的顺序的数字，再将list中的数字按顺序转移到数组
 */
public class LeeCode1389 {


    public int[] createTargetArray(int[] nums, int[] index) {
        int []res = new int[nums.length];
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            list.add(index[i],nums[i]);
        }
        for (int i = 0; i < nums.length; i++) {
            res[i] = list.get(i);
        }
        return res;
    }

    public static void main(String[] args) {
        System.out.println(new LeeCode1389().createTargetArray(new int[]{0, 1, 2, 3, 4}, new int[]{0, 1, 2, 2, 1}));
    }
}
